package com.sl.springmvc.swagger.controller;


import com.sl.springmvc.swagger.bean.User;
import com.sl.springmvc.swagger.service.UserService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class IndexController {

    @Autowired
    private UserService userService;


    @RequestMapping(value = "index", method = RequestMethod.GET)
    @ApiOperation(value = "get all user", notes = "It is return all user information", tags = { "findAllUser", }, produces = "application/json")
    @ApiResponses(value = { @ApiResponse(code = 404, message = "Not Found", response = Void.class) })
    public List<User> index(){
       return userService.findAll();
    }

    @RequestMapping(value = "findUserByName", method = RequestMethod.GET)
    @ApiOperation(value = "get user by name", httpMethod = "GET", notes = "It is return a user information", tags = { "findUserByName", }, produces = "application/json")
    @ApiResponses(value = { @ApiResponse(code = 404, message = "Not Found", response = Void.class) })
    public User findUserByName(@ApiParam(value="userName", required = true)
                               @RequestParam(value = "userName", required = false) String userName){
        return userService.findUserByName(userName);
    }
}
